package com.cirkana.viewer.route.model.gpx;

import java.io.DataInputStream;
import java.io.DataOutputStream;

import com.cirkana.serial.SerializablePassData;
import com.cirkana.serial.SerializationException;

public class Metadata extends SerializablePassData {

	private String name;
	private String desc;
	private String author;
	private String preview;

	// TODO: Should be protected
	public Metadata() {
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public void setPreview(String preview) {
		this.preview = preview;
	}

	public String getPreview() {
		return preview;
	}

	@Override
	public void serialize(DataOutputStream out) throws SerializationException {
		serializeString(this.name, out);
		serializeString(this.desc, out);
		serializeString(this.author, out);
		serializeString(this.preview, out);
	}

	@Override
	public void deserialize(DataInputStream in) throws SerializationException {
		this.name = deserializeString(in);
		this.desc = deserializeString(in);
		this.author = deserializeString(in);
		this.preview = deserializeString(in);
	}

	@Override
	public String toString() {
		StringBuilder s = new StringBuilder("{");

		s.append("name=");
		if (this.name == null)
			s.append("(null)");
		else
			s.append(this.name);
		s.append(",desc=");
		if (this.desc == null)
			s.append("(null)");
		else
			s.append(this.desc);
		s.append(",author=");
		if (this.author == null)
			s.append("(null)");
		else
			s.append(this.author);
		s.append(",preview=");
		if (this.preview == null)
			s.append("(null)");
		else
			s.append(this.preview);
		s.append("}");

		return s.toString();
	}

}
